package CCodeGenerator;

use FindBin;
use Template;
use File::Spec;

use Signature;
use TinyMessage;

sub generate {
	my ($module, $dir) = @_;
	
	my $moduleName = stringfy($module->class());
	
	open(my $f, ">$dir/$moduleName.cpp") || fatal 'F_FILE_GENERATION', "$dir/$moduleName.cpp", $!;
	
	my $tt = Template->new({
		INCLUDE_PATH => "$FindBin::Bin/../templates/",
		INTERPOLATE  => 1,
#		STRICT => 1,
        VARIABLES => {
            module => $module,
            includes => $module->includes_rel($dir),
            version => 'Perl IOCC 0.27',
            signature => \&signature,
            stringfy => \&stringfy,
        },
        OUTPUT => $f,
#        PRE_CHOMP  => 1,
#    	POST_CHOMP => 1
	}) || fatal 'F_TT_ERROR', $Template::ERROR;
	
    $tt->process('module') || fatal 'F_TT_ERROR', $tt->error();
    
	close($f);
}


1;